package com.letoken.platform.pub.configuration;

import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JasyptConfiguration {

//    private static String passwowrd = "A1A239E51F75DE5FB26A9D30F3A51836";
//
//    public static void initPassword() {
//        System.setProperty("jasypt.encryptor.password", passwowrd);
//    }

    @Bean
    public  PooledPBEStringEncryptor encryptor() {
        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        encryptor.setConfig(config());
        return encryptor;
    }



    @Bean
    public  EnvironmentStringPBEConfig config() {
//        System.setProperty("jasypt.encryptor.password", "");
        EnvironmentStringPBEConfig config = new EnvironmentStringPBEConfig();
        config.setPasswordEnvName("APP_ENCRYPTION_PASSWORD");
        config.setAlgorithm("PBEWithMD5AndDES");
        config.setKeyObtentionIterations("1000");
        config.setPoolSize("1");
        config.setProviderName("SunJCE");
        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        config.setStringOutputType("base64");
        return config;
    }


}

